//
//  NewAMIO.h
//  RunSketch
//
//  Created by Brian on 10/18/09.
//  Copyright 2009 Tellart. All rights reserved.
//

#import <Foundation/Foundation.h>
#include <AudioToolbox/AudioToolbox.h>
#import "AMIOAudioSampleFile.h"
#import <AVFoundation/AVFoundation.h>

#define AMIOAmplitudeValue float

@interface NewAMIO : NSObject {
    
    AVAudioRecorder *recorder;

	AMIOAudioSampleFile *carrierSampleFile;
    BOOL enableCarrierTone;
    BOOL inputAvailable;

    double lowpassLevels[2];
    double midrangeLevels[2];
    double highpassLevels[2];
    
}

@property (nonatomic, retain) AVAudioRecorder *recorder;
@property (nonatomic, retain) AMIOAudioSampleFile *carrierSampleFile;
@property BOOL enableCarrierTone;
@property BOOL inputAvailable;

static AMIOAmplitudeValue GetAmplitudeFromFrameValue(UInt32 fr);

-(void)_setupSession;
-(void)_setupAV;
-(void)_setupAU;
-(void) _setupSample:(NSString*)pathToSample;

- (void)initAudio:(NSString*)pathToSample;
- (void)setCarrierTone:(BOOL)state;

- (float)peakPowerForChannel:(NSUInteger)channelNumber;
- (float)averagePowerForChannel:(NSUInteger)channelNumber;
- (float)lowpassPowerForChannel:(int)channelNumber;
- (float)midrangePowerForChannel:(int)channelNumber;
- (float)highpassPowerForChannel:(int)channelNumber;

-(OSStatus)start;
-(OSStatus)stop;

void propListener(	void *                  inClientData,
					AudioSessionPropertyID	inID,
					UInt32                  inDataSize,
					const void *            inData);

    AudioComponentInstance outputAudioUnit;
    //AudioComponentInstance inputAudioUnit;
    AudioStreamBasicDescription outputAudioFormat;
    AudioStreamBasicDescription inputAudioFormat;
    BOOL initialized;

@end
